package com.gitee.sparta.common.helpers;


import com.gitee.sparta.common.SpartaConstant;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;
import java.util.Locale;

/**
 * @author zyred
 * @since v 0.0.2
 */
public class IsolationHelper {

    /**
     * 隔离
     *
     * @param serverId  serverId
     * @return          isolation
     */
    public static String isolation (Integer serverId) {
        String isolation = DigestUtils.md5DigestAsHex(String.valueOf(serverId)
                .getBytes(StandardCharsets.UTF_8)).toUpperCase(Locale.ROOT);
        return isolation.substring(0, SpartaConstant.ISOLATION_LENGTH);
//        return String.valueOf(serverId);
    }

}
